package com.bianmaba.beans.datacollection;

import com.bianmaba.dc.bean.TaskStatus;
import com.bianmaba.spring.data.jpa.domain.annotations.QueryCacheable;
import com.bianmaba.spring.data.jpa.domain.entity.UuidIdentityEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.util.Date;


@Entity
@DynamicUpdate()
@DynamicInsert()
//此注解重新定义为是否开始查询缓存
@QueryCacheable
//此注解表示此类支持二级缓存，缓存名称为：defaultEntityCache
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TaskInstance extends UuidIdentityEntity {

    @Column()
    private String name;
    @Column(name = "[group]")
    private String group;
    @Column()
    private Date startTime;
    @Column()
    private Date endTime;
    @Column()
    private Integer status = TaskStatus.WAIT.getIndex();
    @Column()
    private String executor;

    @ManyToOne(optional = false)
    @JoinColumn(name = "collection_task_id")
    private CollectionTask collectionTask;

    @ManyToOne()
    @JoinColumn(name = "collection_schedule_id")
    private CollectionSchedule collectionSchedule;

    public static TaskInstance of(String taskId) {
        TaskInstance task = new TaskInstance();
        task.setId(taskId);
        return task;
    }

}
